package com.mida.app.knw.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mida.app.knw.service.DetailCodingSystemService;
import com.mida.dms.mdm.dto.DetailCodingSystemCitationDto;
import com.mida.dms.mdm.param.DataSetPageParam;
import com.mida.dms.mdm.pojo.auto.MsdDataSet;
import com.mida.dms.mdm.vo.DetailCodingSystemPageVo;
import com.mida.dms.mdm.vo.PullDownMenuVO;
import com.mida.tool.common.result.ListResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: DetailCodingSystemController
 * @Description: TODO
 * @Author: wang xiao le
 * @Date: 2021/6/24 19:45
 **/
@RestController
@RequestMapping("/knwConceptual")
@CrossOrigin
@Slf4j
public class DetailCodingSystemController {
    @Autowired
    private DetailCodingSystemService detailCodingSystemService;

    /**
     * 1.根据编码体系标志符获取值集列表
     *
     * @param coding 初始化模板报告请求参数
     * @return
     */
    @GetMapping("/drawer")
    @ResponseBody
    public ListResult<List<PullDownMenuVO>> drawer(String coding) throws Exception {
        ListResult listResult;
        try {
            return detailCodingSystemService.drawer2(coding, null, false);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            listResult = new ListResult();
            listResult.setMessage("获取值集列表失败");
            listResult.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
            return listResult;
        }

    }
    /**
     * 2.根据概念soid查询值集（概念中使用）
     *
     * @param dataSetPageParam 请求参数
     * @return
     */
    @PostMapping(
            value = {"/findListByConceptSoid"},
            produces = {"application/json"}
    )
    ListResult<Page<MsdDataSet>> findListByConceptSoid(@RequestBody DataSetPageParam dataSetPageParam){
        ListResult listResult=new ListResult<>();
        try {
            return  detailCodingSystemService.findListByConceptSoid(dataSetPageParam);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            listResult = new ListResult();
            listResult.setMessage("查询值集失败");
            listResult.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
            return listResult;
        }

    }

    /**
     * 3.查询所有编码体系（概念中使用）
     *
     * @param vo 请求参数
     * @return
     */
    @PostMapping(
            value = {"/findAll"},
            produces = {"application/json;charset=UTF-8"}
    )
    ListResult<List<DetailCodingSystemCitationDto>> findAll(@RequestBody(required = false) DetailCodingSystemPageVo vo){
        ListResult listResult;
        try {
            return detailCodingSystemService.findAll(vo);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            listResult = new ListResult();
            listResult.setMessage("查询所有编码体系失败");
            listResult.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
            return listResult;
        }
    }
    /**
     * 4.根据编码体系soid查询值集（实例中使用）
     *
     * @param derailCodingSystemSoid 请求参数
     * @param search 请求参数
     * @return
     */
    @GetMapping(value = "/getDataSetList")
    @ResponseBody
    public ListResult<List<MsdDataSet>> getDataSetList(Long derailCodingSystemSoid, String search) {
        ListResult listResult;
        try {
            return detailCodingSystemService.getDataSetList(derailCodingSystemSoid,search);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            listResult = new ListResult();
            listResult.setMessage("获取值集列表失败");
            listResult.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
            return listResult;
        }
    }

}
